package figure8.GUI;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BoxLayout;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import figure8.LoopTiming;
import figure8.GUI.DelayPanel.NoteLen;
import figure8.GUI.EffectWindow.Effect;

public class ReversePanel extends EffectPanel {
	public enum NoteLen {Demisemiquaver, Dotted_Demisemiquaver,
						 Semiquaver,     Dotted_Semiquaver,
						 Quaver,         Dotted_Quaver,
						 Crotchet,       Dotted_Crotchet,
						 Minim,          Dotted_Minim,
						 Semibreve                              };
    final JComboBox noteLen = new JComboBox(NoteLen.values());;

	final EffectPanel effPan = this;
	final EffectWindow effWindow;

	Color BG = new Color(51,51,51);
	Color FG = Color.WHITE;
	
	public ReversePanel(EffectWindow effWin){ this(effWin, Effect.REVERSE, 10); }

	public ReversePanel(EffectWindow effWin, Effect effType, double noteLenSet){
		super(effType, effWin);
		this.effWindow = effWin;
		
		JPanel background = new JPanel();
		background.setBackground(BG);
		background.setForeground(FG);

		JPanel titlePanel = new JPanel();
		titlePanel.setLayout(new GridBagLayout());
		titlePanel.setBackground(BG);
		titlePanel.setForeground(FG);

		//DELETE
		JLabel del = new JLabel("x");
		del.setForeground(FG);
		del.setFont(new Font(Font.DIALOG, Font.BOLD, 15));
		
		del.addMouseListener(new MouseListener() {
			public void mouseClicked(MouseEvent arg0) {	}
			public void mouseEntered(MouseEvent arg0) {	}
			public void mouseExited(MouseEvent arg0) { }
			public void mouseReleased(MouseEvent arg0) { }
			public void mousePressed(MouseEvent arg0) {
				effWindow.effPanelDeletion(effPan);
			}
		});
		
		//TITLE
		JLabel title = 
		new JLabel("   " + "R3V3RS3", JLabel.CENTER);
		title.setFont(new Font(Font.DIALOG, Font.BOLD, 21));
		title.setPreferredSize(new Dimension(220, 20));
		title.setForeground(FG);
		
		GridBagConstraints a = new GridBagConstraints();
		a.fill = GridBagConstraints.BOTH;
		a.anchor = a.CENTER;
		a.gridwidth = GridBagConstraints.RELATIVE;
		titlePanel.add(title, a);
		a.anchor = a.FIRST_LINE_END;
		a.ipadx = 30;
		a.gridwidth = GridBagConstraints.REMAINDER;
		titlePanel.add(del, a);

		//DELAY LENGTH COL
		
		noteLen.setFont(new Font(Font.MONOSPACED,Font.PLAIN, 11));
		noteLen.setForeground(Color.BLACK);
		noteLen.setSelectedIndex((int)noteLenSet);
				
		background.add(titlePanel);
		background.add(noteLen);
		
		this.add(background);
	}
	
	public double getNoteLen() { return noteLen.getSelectedIndex(); }
	
	public double getBPM() { 
		LoopTiming timing = effWindow.getLoopTiming();
		return timing.getTempo();	
	}
		
	public double[] getSettings() {
		double[] settings = {getNoteLen(),  getBPM()};
		return settings;
	}

}

